package uestc.lj.gulishop.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页面需要的实体类
 *
 * @Author:Crazlee
 * @Date:2021/6/15
 */
public class OrderConfirmVO {
    /**
     * 收获地址
     */
    @Getter
    @Setter
    private List<MemberAddressVO> address;
    /**
     * 选中的购物项
     */
    @Getter
    @Setter
    private List<OrderItemVO> items;

    /**
     * 会员积分
     */
    @Getter
    @Setter
    private Integer integration;
    /**
     * 订单总额
     */
    private BigDecimal total;
    /**
     * 应付价格
     */
    private BigDecimal payPrice;
    /**
     * 表示每个商品是否有库存
     */
    @Getter
    @Setter
    Map<Long, Boolean> stocks;

    /**
     * 表示订单的唯一令牌
     */
    @Getter
    @Setter
    private String orderToken;

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVO item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVO item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public Integer getCount() {
        Integer count = 0;
        if (items != null) {
            for (OrderItemVO item : items) {
                count += item.getCount();
            }
        }
        return count;
    }
}
